/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yami.shop.bean.model.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface UserMapper extends BaseMapper<User> {

	User getUserByBizUserId(@Param("appId")Integer appId, @Param("bizUserId")String bizUserId);

	User getUserByUserMail(@Param("userMail") String userMail);
/*@Select("select * from tz_user where user_mobile = #{userMobile}")
	User getUserByUserMobile(@Param("userMobile") String userMobile);*/

	@Select("select * from tz_user where user_id=#{uid}")
	User getUserById(String uid);

	@Select("select user_id,nickName,pic,provinceId,province,city,cityId,area,areaId,userLabels,isOnline from tz_user where user_id=#{uid}")
	User getBriefUserById(String uid);

	@Update("update tz_user set like_me_count = like_me_count + 1 where user_id = #{uid}")
	int addOneUserLike(String uid);

	@Update("update tz_user set like_me_count = like_me_count - 1 where user_id = #{uid}")
	int subOneUserLike(String uid);

	@Update("update tz_user set today_unlock_surplus = today_unlock_surplus - 1 where user_id = #{uid}")
	int subOneUserUnlockSurplus(String uid);

	@Update("update tz_user set reg_gift_num = reg_gift_num - 1 where user_id = #{uid}")
	int deitGiftNumById(String uid);

	@Update("update tz_user set inv_gift_num = inv_gift_num - 1 where user_id = #{uid}")
	int deitInvGiftNumById(String uid);

	@Update("update tz_user set inv_ple_num = inv_ple_num - 1 where user_id = #{uid}")
	int editInvPleNumById(String uid);

	@Update("update tz_user set diamond_num = diamond_num - #{diamondAmount} where user_id = #{uid}")
	int subOneUserDiamond(@Param("uid") String uid,@Param("diamondAmount") Integer diamondAmount);

	@Select("select count(*) from tz_user where invitatio_code = #{invitatioCode}")
	int invitatioCodeRepeat(String invitatioCode);

	//赠送上级邀请福利
	@Update("update tz_user set inv_gift_endtime = date_sub(NOW(),interval -1 day),inv_gift_num = inv_gift_num+3 WHERE invitatio_code = #{upp}")
	int uppCodeRepeat(@Param("upp") String upp);

	//赠送上级 邀请人首充VIP福利
	@Update("update tz_user set inv_ple_endtime = date_sub(NOW(),interval -2 day),inv_ple_num = inv_ple_num+6 WHERE invitatio_code = #{upp}")
	int uppCodeRepeatVip(@Param("upp") String upp);

	@Select("SELECT sex from tz_user where invitatio_code = #{upp}")
	String uppJudge(String upp);

	@Update("update ch_unlock_record set status = 2 where passed_time < NOW() and status = 1")
	void deitJieSuoStatus();

	@Update("update tz_user set today_unlock_surplus = 10 where vip_end_time < NOW() and is_vip = 1")
	void vipUpdate();

	@Update("update tz_user set is_vip = 0,today_unlock_surplus = 0 where vip_end_time < NOW() and is_vip = 1")
	void vipStageTime();

	@Update("update tz_user set inv_gift_num = 0 where inv_gift_endtime < NOW()")
	void invGiftTime();

	@Update("update tz_user set inv_ple_num = 0 where inv_ple_endtime < NOW() ")
	void invPleTime();

	@Select("select count(*) from ch_view_user_record where from_user_id = #{fromId} and looked_user_id = #{lookedId}")
	int queryChaKan(@Param("fromId")String fromId,@Param("lookedId")String lookedId);

	@Select("select * from tz_user")
	List<User> getallUser();

	@Update("UPDATE tz_user set heartbeat = now(),is_online = 1 where user_id = #{uid}")
	int editIsOnlz(@Param("uid")String uid);

	@Update("update tz_user set is_online = 0 where round((UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(heartbeat))/60) > 2")
	int editIsOnlx();
}
